"""
-------------------------------
- File_Name: ctx.py
- Date: 2025/2/19
- Author: yangzhide
- Email: xxzjyzd@126.com
- Description: 异步上下文管理
-------------------------------
"""


import contextvars

from starlette.background import BackgroundTasks

from pydantic import BaseModel

class CtxUser(BaseModel):
    user_name: str | None
    user_code: str | None
    user_role_id: list[int] | None
    user_role_code: list[str] | None

# 用户对象
CTX_USER: contextvars.ContextVar[CtxUser | None] = contextvars.ContextVar("user", default=None)

CTX_BG_TASKS: contextvars.ContextVar[BackgroundTasks | None] = contextvars.ContextVar("bg_tasks", default=None)

